package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PurchaseOrganizations;
import com.ruoyi.system.service.IPurchaseOrganizationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购组织Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/system/organizations")
public class PurchaseOrganizationsController extends BaseController
{
    @Autowired
    private IPurchaseOrganizationsService purchaseOrganizationsService;

    /**
     * 查询采购组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:organizations:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseOrganizations purchaseOrganizations)
    {
        startPage();
        List<PurchaseOrganizations> list = purchaseOrganizationsService.selectPurchaseOrganizationsList(purchaseOrganizations);
        return getDataTable(list);
    }

    /**
     * 导出采购组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:organizations:export')")
    @Log(title = "采购组织", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseOrganizations purchaseOrganizations)
    {
        List<PurchaseOrganizations> list = purchaseOrganizationsService.selectPurchaseOrganizationsList(purchaseOrganizations);
        ExcelUtil<PurchaseOrganizations> util = new ExcelUtil<PurchaseOrganizations>(PurchaseOrganizations.class);
        util.exportExcel(response, list, "采购组织数据");
    }

    /**
     * 获取采购组织详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:organizations:query')")
    @GetMapping(value = "/{poId}")
    public AjaxResult getInfo(@PathVariable("poId") Long poId)
    {
        return success(purchaseOrganizationsService.selectPurchaseOrganizationsByPoId(poId));
    }

    /**
     * 新增采购组织
     */
    @PreAuthorize("@ss.hasPermi('system:organizations:add')")
    @Log(title = "采购组织", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseOrganizations purchaseOrganizations)
    {
        return toAjax(purchaseOrganizationsService.insertPurchaseOrganizations(purchaseOrganizations));
    }

    /**
     * 修改采购组织
     */
    @PreAuthorize("@ss.hasPermi('system:organizations:edit')")
    @Log(title = "采购组织", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseOrganizations purchaseOrganizations)
    {
        return toAjax(purchaseOrganizationsService.updatePurchaseOrganizations(purchaseOrganizations));
    }

    /**
     * 删除采购组织
     */
    @PreAuthorize("@ss.hasPermi('system:organizations:remove')")
    @Log(title = "采购组织", businessType = BusinessType.DELETE)
	@DeleteMapping("/{poIds}")
    public AjaxResult remove(@PathVariable Long[] poIds)
    {
        return toAjax(purchaseOrganizationsService.deletePurchaseOrganizationsByPoIds(poIds));
    }
}
